<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the parseIPv6Address method from the Uri class, for the Dart programming language.">
  <title>parseIPv6Address method - Uri class - dart:core library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">
  
</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">manage_calendar_events</a></li>
    <li><a href="dart-core/dart-core-library.html">dart:core</a></li>
    <li><a href="dart-core/Uri-class.html">Uri</a></li>
    <li class="self-crumb">parseIPv6Address method</li>
  </ol>
  <div class="self-name">parseIPv6Address</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div id="dartdoc-sidebar-left" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <header id="header-search-sidebar" class="hidden-l">
      <form class="search-sidebar" role="search">
        <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
      </form>
    </header>
    
    <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
      <li><a href="index.html">manage_calendar_events</a></li>
      <li><a href="dart-core/dart-core-library.html">dart:core</a></li>
      <li><a href="dart-core/Uri-class.html">Uri</a></li>
      <li class="self-crumb">parseIPv6Address method</li>
    </ol>
    
    <h5>Uri class</h5>
    <ol>
      <li class="section-title"><a href="dart-core/Uri-class.html#constructors">Constructors</a></li>
      <li><a href="dart-core/Uri/Uri.html">Uri</a></li>
      <li><a href="dart-core/Uri/Uri.dataFromBytes.html">dataFromBytes</a></li>
      <li><a href="dart-core/Uri/Uri.dataFromString.html">dataFromString</a></li>
      <li><a href="dart-core/Uri/Uri.directory.html">directory</a></li>
      <li><a href="dart-core/Uri/Uri.file.html">file</a></li>
      <li><a href="dart-core/Uri/Uri.http.html">http</a></li>
      <li><a href="dart-core/Uri/Uri.https.html">https</a></li>
    
      <li class="section-title">
        <a href="dart-core/Uri-class.html#instance-properties">Properties</a>
      </li>
      <li><a href="dart-core/Uri/authority.html">authority</a></li>
      <li><a href="dart-core/Uri/data.html">data</a></li>
      <li><a href="dart-core/Uri/fragment.html">fragment</a></li>
      <li><a href="dart-core/Uri/hasAbsolutePath.html">hasAbsolutePath</a></li>
      <li><a href="dart-core/Uri/hasAuthority.html">hasAuthority</a></li>
      <li><a href="dart-core/Uri/hasEmptyPath.html">hasEmptyPath</a></li>
      <li><a href="dart-core/Uri/hasFragment.html">hasFragment</a></li>
      <li><a href="dart-core/Uri/hashCode.html">hashCode</a></li>
      <li><a href="dart-core/Uri/hasPort.html">hasPort</a></li>
      <li><a href="dart-core/Uri/hasQuery.html">hasQuery</a></li>
      <li><a href="dart-core/Uri/hasScheme.html">hasScheme</a></li>
      <li><a href="dart-core/Uri/host.html">host</a></li>
      <li><a href="dart-core/Uri/isAbsolute.html">isAbsolute</a></li>
      <li><a href="dart-core/Uri/origin.html">origin</a></li>
      <li><a href="dart-core/Uri/path.html">path</a></li>
      <li><a href="dart-core/Uri/pathSegments.html">pathSegments</a></li>
      <li><a href="dart-core/Uri/port.html">port</a></li>
      <li><a href="dart-core/Uri/query.html">query</a></li>
      <li><a href="dart-core/Uri/queryParameters.html">queryParameters</a></li>
      <li><a href="dart-core/Uri/queryParametersAll.html">queryParametersAll</a></li>
      <li><a href="dart-core/Uri/scheme.html">scheme</a></li>
      <li><a href="dart-core/Uri/userInfo.html">userInfo</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
      <li class="section-title"><a href="dart-core/Uri-class.html#instance-methods">Methods</a></li>
      <li><a href="dart-core/Uri/isScheme.html">isScheme</a></li>
      <li><a href="dart-core/Uri/normalizePath.html">normalizePath</a></li>
      <li><a href="dart-core/Uri/removeFragment.html">removeFragment</a></li>
      <li><a href="dart-core/Uri/replace.html">replace</a></li>
      <li><a href="dart-core/Uri/resolve.html">resolve</a></li>
      <li><a href="dart-core/Uri/resolveUri.html">resolveUri</a></li>
      <li><a href="dart-core/Uri/toFilePath.html">toFilePath</a></li>
      <li><a href="dart-core/Uri/toString.html">toString</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
    
      <li class="section-title"><a href="dart-core/Uri-class.html#operators">Operators</a></li>
      <li><a href="dart-core/Uri/operator_equals.html">operator ==</a></li>
    
      <li class="section-title"><a href="dart-core/Uri-class.html#static-properties">Static properties</a></li>
      <li><a href="dart-core/Uri/base.html">base</a></li>
    
      <li class="section-title"><a href="dart-core/Uri-class.html#static-methods">Static methods</a></li>
      <li><a href="dart-core/Uri/decodeComponent.html">decodeComponent</a></li>
      <li><a href="dart-core/Uri/decodeFull.html">decodeFull</a></li>
      <li><a href="dart-core/Uri/decodeQueryComponent.html">decodeQueryComponent</a></li>
      <li><a href="dart-core/Uri/encodeComponent.html">encodeComponent</a></li>
      <li><a href="dart-core/Uri/encodeFull.html">encodeFull</a></li>
      <li><a href="dart-core/Uri/encodeQueryComponent.html">encodeQueryComponent</a></li>
      <li><a href="dart-core/Uri/parse.html">parse</a></li>
      <li><a href="dart-core/Uri/parseIPv4Address.html">parseIPv4Address</a></li>
      <li><a href="dart-core/Uri/parseIPv6Address.html">parseIPv6Address</a></li>
      <li><a href="dart-core/Uri/splitQueryString.html">splitQueryString</a></li>
      <li><a href="dart-core/Uri/tryParse.html">tryParse</a></li>
    
    </ol>
  </div><!--/.sidebar-offcanvas-->

  <div id="dartdoc-main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
      <div><h1><span class="kind-method">parseIPv6Address</span> method</h1></div>

    <section class="multi-line-signature">
      <span class="returntype"><a href="dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="dart-core/int-class.html">int</a></span>&gt;</span></span>
            <span class="name ">parseIPv6Address</span>
(<wbr><span class="parameter" id="parseIPv6Address-param-host"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">host</span>, [</span> <span class="parameter" id="parseIPv6Address-param-start"><span class="type-annotation"><a href="dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span> = <span class="default-value">0</span>, </span> <span class="parameter" id="parseIPv6Address-param-end"><span class="type-annotation"><a href="dart-core/int-class.html">int</a></span> <span class="parameter-name">end</span></span> ])
      
    </section>
    <section class="desc markdown">
      <p>Parse the <code>host</code> as an IP version 6 (IPv6) address, returning the address
as a list of 16 bytes in network byte order (big endian).</p>
<p>Throws a <a href="dart-core/FormatException-class.html">FormatException</a> if <code>host</code> is not a valid IPv6 address
representation.</p>
<p>Acts on the substring from <code>start</code> to <code>end</code>. If <code>end</code> is omitted, it
defaults ot the end of the string.</p>
<p>Some examples of IPv6 addresses:</p><ul><li>::1</li><li>FEDC:BA98:7654:3210:FEDC:BA98:7654:3210</li><li>3ffe:2a00💯7031::1</li><li>::FFFF:129.144.52.38</li><li>2010:836B:4179::836B:4179</li></ul>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span></h2>
      <pre class="language-dart"><code class="language-dart">static List&lt;int&gt; parseIPv6Address(String host, [int start = 0, int end]) {
  end ??= host.length;
  &#47;&#47; An IPv6 address consists of exactly 8 parts of 1-4 hex digits, separated
  &#47;&#47; by `:`&#39;s, with the following exceptions:
  &#47;&#47;
  &#47;&#47;  - One (and only one) wildcard (`::`) may be present, representing a fill
  &#47;&#47;    of 0&#39;s. The IPv6 `::` is thus 16 bytes of `0`.
  &#47;&#47;  - The last two parts may be replaced by an IPv4 &quot;dotted-quad&quot; address.

  &#47;&#47; Helper function for reporting a badly formatted IPv6 address.
  void error(String msg, [position]) {
    throw FormatException(&#39;Illegal IPv6 address, $msg&#39;, host, position);
  }

  &#47;&#47; Parse a hex block.
  int parseHex(int start, int end) {
    if (end - start &gt; 4) {
      error(&#39;an IPv6 part can only contain a maximum of 4 hex digits&#39;, start);
    }
    int value = int.parse(host.substring(start, end), radix: 16);
    if (value &lt; 0 || value &gt; 0xFFFF) {
      error(&#39;each part must be in the range of `0x0..0xFFFF`&#39;, start);
    }
    return value;
  }

  if (host.length &lt; 2) error(&#39;address is too short&#39;);
  List&lt;int&gt; parts = [];
  bool wildcardSeen = false;
  &#47;&#47; Set if seeing a &quot;.&quot;, suggesting that there is an IPv4 address.
  bool seenDot = false;
  int partStart = start;
  &#47;&#47; Parse all parts, except a potential last one.
  for (int i = start; i &lt; end; i++) {
    int char = host.codeUnitAt(i);
    if (char == _COLON) {
      if (i == start) {
        &#47;&#47; If we see a `:` in the beginning, expect wildcard.
        i++;
        if (host.codeUnitAt(i) != _COLON) {
          error(&#39;invalid start colon.&#39;, i);
        }
        partStart = i;
      }
      if (i == partStart) {
        &#47;&#47; Wildcard. We only allow one.
        if (wildcardSeen) {
          error(&#39;only one wildcard `::` is allowed&#39;, i);
        }
        wildcardSeen = true;
        parts.add(-1);
      } else {
        &#47;&#47; Found a single colon. Parse [partStart..i] as a hex entry.
        parts.add(parseHex(partStart, i));
      }
      partStart = i + 1;
    } else if (char == _DOT) {
      seenDot = true;
    }
  }
  if (parts.length == 0) error(&#39;too few parts&#39;);
  bool atEnd = (partStart == end);
  bool isLastWildcard = (parts.last == -1);
  if (atEnd &amp;&amp; !isLastWildcard) {
    error(&#39;expected a part after last `:`&#39;, end);
  }
  if (!atEnd) {
    if (!seenDot) {
      parts.add(parseHex(partStart, end));
    } else {
      List&lt;int&gt; last = _parseIPv4Address(host, partStart, end);
      parts.add(last[0] &lt;&lt; 8 | last[1]);
      parts.add(last[2] &lt;&lt; 8 | last[3]);
    }
  }
  if (wildcardSeen) {
    if (parts.length &gt; 7) {
      error(&#39;an address with a wildcard must have less than 7 parts&#39;);
    }
  } else if (parts.length != 8) {
    error(&#39;an address without a wildcard must contain exactly 8 parts&#39;);
  }
  List&lt;int&gt; bytes = Uint8List(16);
  for (int i = 0, index = 0; i &lt; parts.length; i++) {
    int value = parts[i];
    if (value == -1) {
      int wildCardLength = 9 - parts.length;
      for (int j = 0; j &lt; wildCardLength; j++) {
        bytes[index] = 0;
        bytes[index + 1] = 0;
        index += 2;
      }
    } else {
      bytes[index] = value &gt;&gt; 8;
      bytes[index + 1] = value &amp; 0xff;
      index += 2;
    }
  }
  return bytes;
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    manage_calendar_events 1.0.1
  </span>

  
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
